package cn.kgc.crowdfundingadminspringboot.service;

import cn.kgc.crowdfundingadminspringboot.mapper.MessageMapper;
import cn.kgc.crowdfundingadminspringboot.pojo.Message;
import cn.kgc.crowdfundingadminspringboot.pojo.MessageExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class MessageServiceImpl implements MessageService {
    @Resource
    MessageMapper messageMapper;
    @Override
    public PageInfo<Message> queryForKeywordWithPage(Integer pageNum, Integer pageSize, String keyword) {
        // 1.开启分页功能
        PageHelper.startPage(pageNum, pageSize);

        // 2.执行查询
        MessageExample roleExample=new MessageExample();
        MessageExample.Criteria criteria = roleExample.createCriteria();
        criteria.andContentLike("%"+keyword+"%");
        List<Message> list = messageMapper.selectByExample(roleExample);
        // 3.封装为PageInfo对象
        PageInfo<Message> rolePageInfo = new PageInfo<>(list);
        return rolePageInfo;
    }

    @Override
    public List<Message> getTagListByIdList(List<Integer> tagLists) {
        // 创建实体类Role对应的Example对象
        MessageExample roleExample = new MessageExample();
        // 在Example对象中封装查询条件
        roleExample.createCriteria().andIdIn(tagLists);
        // 执行查询
        return messageMapper.selectByExample(roleExample);
    }

    @Override
    public void batchRemove(List<Integer> roleIdList) {
        MessageExample roleExample = new MessageExample();
        roleExample.createCriteria().andIdIn(roleIdList);
        messageMapper.deleteByExample(roleExample);
    }

    @Override
    public void saveRole(Integer memberid, String content, String senddate) {
        messageMapper.insert(new Message(memberid,content,senddate));
    }

    @Override
    public void updateRole(Message tag) {
        messageMapper.updateByPrimaryKey(tag);
    }


}
